home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / MSDOS_FS.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  12KB  |  323 lines

  1. #ifndef _LINUX_MSDOS_FS_H
  2. #define _LINUX_MSDOS_FS_H
  3.  
  4. /*
  5.  * The MS-DOS filesystem constants/structures
  6.  */
  7. #include <linux/fs.h>
  8. #include <linux/stat.h>
  9. #include <linux/fd.h>
  10.  
  11. #include <asm/byteorder.h>
  12.  
  13. #define MSDOS_ROOT_INO  1 /* == MINIX_ROOT_INO */
  14. #define SECTOR_SIZE     512 /* sector size (bytes) */
  15. #define SECTOR_BITS    9 /* log2(SECTOR_SIZE) */
  16. #define MSDOS_DPB    (MSDOS_DPS) /* dir entries per block */
  17. #define MSDOS_DPB_BITS    4 /* log2(MSDOS_DPB) */
  18. #define MSDOS_DPS    (SECTOR_SIZE/sizeof(struct msdos_dir_entry))
  19. #define MSDOS_DPS_BITS    4 /* log2(MSDOS_DPS) */
  20. #define MSDOS_DIR_BITS    5 /* log2(sizeof(struct msdos_dir_entry)) */
  21.  
  22. #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
  23.  
  24. #define FAT_CACHE    8 /* FAT cache size */
  25.  
  26. #define MSDOS_MAX_EXTRA    3 /* tolerate up to that number of clusters which are
  27.                  inaccessible because the FAT is too short */
  28.  
  29. #define ATTR_RO      1  /* read-only */
  30. #define ATTR_HIDDEN  2  /* hidden */
  31. #define ATTR_SYS     4  /* system */
  32. #define ATTR_VOLUME  8  /* volume label */
  33. #define ATTR_DIR     16 /* directory */
  34. #define ATTR_ARCH    32 /* archived */
  35.  
  36. #define ATTR_NONE    0 /* no attribute bits */
  37. #define ATTR_UNUSED  (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
  38.     /* attribute bits that are copied "as is" */
  39. #define ATTR_EXT     (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
  40.     /* bits that are used by the Windows 95/Windows NT extended FAT */
  41.  
  42. #define ATTR_DIR_READ_BOTH 512 /* read both short and long names from the
  43.                 * vfat filesystem.  This is used by Samba
  44.                 * to export the vfat filesystem with correct
  45.                 * shortnames. */
  46. #define ATTR_DIR_READ_SHORT 1024
  47.  
  48. #define CASE_LOWER_BASE 8    /* base is lower case */
  49. #define CASE_LOWER_EXT  16    /* extension is lower case */
  50.  
  51. #define SCAN_ANY     0  /* either hidden or not */
  52. #define SCAN_HID     1  /* only hidden */
  53. #define SCAN_NOTHID  2  /* only not hidden */
  54. #define SCAN_NOTANY  3  /* test name, then use SCAN_HID or SCAN_NOTHID */
  55.  
  56. #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
  57. #define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG || \
  58.   *(const unsigned char *) (n) == FD_FILL_BYTE)
  59.  
  60. #define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
  61.     /* valid file mode bits */
  62.  
  63. #define MSDOS_SB(s) (&((s)->u.msdos_sb))
  64. #define MSDOS_I(i) (&((i)->u.msdos_i))
  65.  
  66. #define MSDOS_NAME 11 /* maximum name length */
  67. #define MSDOS_LONGNAME 256 /* maximum name length */
  68. #define MSDOS_SLOTS 21  /* max # of slots needed for short and long names */
  69. #define MSDOS_DOT    ".          " /* ".", padded to MSDOS_NAME chars */
  70. #define MSDOS_DOTDOT "..         " /* "..", padded to MSDOS_NAME chars */
  71.  
  72. #define MSDOS_FAT12 4078 /* maximum number of clusters in a 12 bit FAT */
  73.  
  74. #define EOF_FAT12 0xFF8        /* standard EOF */
  75. #define EOF_FAT16 0xFFF8
  76. #define EOF_FAT32 0xFFFFFF8
  77. #define EOF_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? EOF_FAT32 : \
  78.     MSDOS_SB(s)->fat_bits == 16 ? EOF_FAT16 : EOF_FAT12)
  79.  
  80. /*
  81.  * Inode flags
  82.  */
  83. #define FAT_BINARY_FL        0x00000001 /* File contains binary data */
  84.  
  85. /*
  86.  * ioctl commands
  87.  */
  88. #define    VFAT_IOCTL_READDIR_BOTH        _IOR('r', 1, struct dirent [2])
  89. #define    VFAT_IOCTL_READDIR_SHORT    _IOR('r', 2, struct dirent [2])
  90.  
  91. /*
  92.  * Conversion from and to little-endian byte order. (no-op on i386/i486)
  93.  *
  94.  * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
  95.  * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
  96.  */
  97.  
  98. #define CF_LE_W(v) le16_to_cpu(v)
  99. #define CF_LE_L(v) le32_to_cpu(v)
  100. #define CT_LE_W(v) cpu_to_le16(v)
  101. #define CT_LE_L(v) cpu_to_le32(v)
  102.  
  103. struct fat_boot_sector {
  104.     __s8    ignored[3];    /* Boot strap short or near jump */
  105.     __s8    system_id[8];    /* Name - can be used to special case
  106.                    partition manager volumes */
  107.     __u8    sector_size[2];    /* bytes per logical sector */
  108.     __u8    cluster_size;    /* sectors/cluster */
  109.     __u16    reserved;    /* reserved sectors */
  110.     __u8    fats;        /* number of FATs */
  111.     __u8    dir_entries[2];    /* root directory entries */
  112.     __u8    sectors[2];    /* number of sectors */
  113.     __u8    media;        /* media code (unused) */
  114.     __u16    fat_length;    /* sectors/FAT */
  115.     __u16    secs_track;    /* sectors per track */
  116.     __u16    heads;        /* number of heads */
  117.     __u32    hidden;        /* hidden sectors (unused) */
  118.     __u32    total_sect;    /* number of sectors (if sectors == 0) */
  119.  
  120.     /* The following fields are only used by FAT32 */
  121.     __u32    fat32_length;    /* sectors/FAT */
  122.     __u16    flags;        /* bit 8: fat mirroring, low 4: active fat */
  123.     __u8    version[2];    /* major, minor filesystem version */
  124.     __u32    root_cluster;    /* first cluster in root directory */
  125.     __u16    info_sector;    /* filesystem info sector */
  126.     __u16    backup_boot;    /* backup boot sector */
  127.     __u16    reserved2[6];    /* Unused */
  128. };
  129.  
  130. struct fat_boot_fsinfo {
  131.     __u32   reserved1;    /* Nothing as far as I can tell */
  132.     __u32   signature;    /* 0x61417272L */
  133.     __u32   free_clusters;    /* Free cluster count.  -1 if unknown */
  134.     __u32   next_cluster;    /* Most recently allocated cluster.
  135.                  * Unused under Linux. */
  136.     __u32   reserved2[4];
  137. };
  138.  
  139. struct msdos_dir_entry {
  140.     __s8    name[8],ext[3];    /* name and extension */
  141.     __u8    attr;        /* attribute bits */
  142.     __u8    lcase;        /* Case for base and extension */
  143.     __u8    ctime_ms;    /* Creation time, milliseconds */
  144.     __u16    ctime;        /* Creation time */
  145.     __u16    cdate;        /* Creation date */
  146.     __u16    adate;        /* Last access date */
  147.     __u16   starthi;    /* High 16 bits of cluster in FAT32 */
  148.     __u16    time,date,start;/* time, date and first cluster */
  149.     __u32    size;        /* file size (in bytes) */
  150. };
  151.  
  152. /* Up to 13 characters of the name */
  153. struct msdos_dir_slot {
  154.     __u8    id;        /* sequence number for slot */
  155.     __u8    name0_4[10];    /* first 5 characters in name */
  156.     __u8    attr;        /* attribute byte */
  157.     __u8    reserved;    /* always 0 */
  158.     __u8    alias_checksum;    /* checksum for 8.3 alias */
  159.     __u8    name5_10[12];    /* 6 more characters in name */
  160.     __u16   start;        /* starting cluster number, 0 in long slots */
  161.     __u8    name11_12[4];    /* last 2 characters in name */
  162. };
  163.  
  164. struct vfat_slot_info {
  165.     int is_long;               /* was the found entry long */
  166.     int long_slots;               /* number of long slots in filename */
  167.     int total_slots;           /* total slots (long and short) */
  168.     loff_t longname_offset;           /* dir offset for longname start */
  169.     loff_t shortname_offset;       /* dir offset for shortname start */
  170.     int ino;               /* ino for the file */
  171. };
  172.  
  173. /* Determine whether this FS has kB-aligned data. */
  174. #define MSDOS_CAN_BMAP(mib) (!(((mib)->cluster_size & 1) || \
  175.     ((mib)->data_start & 1)))
  176.  
  177. /* Convert attribute bits and a mask to the UNIX mode. */
  178. #define MSDOS_MKMODE(a,m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
  179.  
  180. /* Convert the UNIX mode to MS-DOS attribute bits. */
  181. #define MSDOS_MKATTR(m) ((m & S_IWUGO) ? ATTR_NONE : ATTR_RO)
  182.  
  183.  
  184. #ifdef __KERNEL__
  185.  
  186. typedef int (*fat_filldir_t)(filldir_t filldir, void *, const char *,
  187.                  int, int, off_t, off_t, int, ino_t);
  188.  
  189. struct fat_cache {
  190.     kdev_t device; /* device number. 0 means unused. */
  191.     int ino; /* inode number. */
  192.     int file_cluster; /* cluster number in the file. */
  193.     int disk_cluster; /* cluster number on disk. */
  194.     struct fat_cache *next; /* next cache entry */
  195. };
  196.  
  197. /* misc.c */
  198. extern int is_binary(char conversion,char *extension);
  199. extern void lock_fat(struct super_block *sb);
  200. extern void unlock_fat(struct super_block *sb);
  201. extern int fat_add_cluster(struct inode *inode);
  202. extern int date_dos2unix(__u16 time, __u16 date);
  203. extern void fat_fs_panic(struct super_block *s,const char *msg);
  204. extern void fat_lock_creation(void);
  205. extern void fat_unlock_creation(void);
  206. extern void fat_date_unix2dos(int unix_date,__u16 *time, __u16 *date);
  207. extern int fat_get_entry(struct inode *dir,loff_t *pos,struct buffer_head **bh,
  208.              struct msdos_dir_entry **de);
  209. extern int fat_scan(struct inode *dir,const char *name,struct buffer_head **res_bh,
  210.             struct msdos_dir_entry **res_de,int *ino,char scantype);
  211. extern int fat_parent_ino(struct inode *dir,int locked);
  212. extern int fat_subdirs(struct inode *dir);
  213. void fat_clusters_flush(struct super_block *sb);
  214.  
  215. /* fat.c */
  216. extern int fat_access(struct super_block *sb,int nr,int new_value);
  217. extern int fat_smap(struct inode *inode,int sector);
  218. extern int fat_free(struct inode *inode,int skip);
  219. void fat_cache_inval_inode(struct inode *inode);
  220. void fat_cache_inval_dev(kdev_t device);
  221. extern void fat_cache_init(void);
  222. void fat_cache_lookup(struct inode *inode,int cluster,int *f_clu,int *d_clu);
  223. void fat_cache_add(struct inode *inode,int f_clu,int d_clu);
  224. int fat_get_cluster(struct inode *inode,int cluster);
  225.  
  226. /* inode.c */
  227. extern int fat_bmap(struct inode *inode,int block);
  228. extern int fat_notify_change(struct dentry *, struct iattr *);
  229. extern void fat_put_inode(struct inode *inode);
  230. extern void fat_delete_inode(struct inode *inode);
  231. extern void fat_put_super(struct super_block *sb);
  232. extern void fat_read_inode(struct inode *inode, struct inode_operations *dir_ops);
  233. extern struct super_block *fat_read_super(struct super_block *s, void *data, int silent);
  234. extern void msdos_put_super(struct super_block *sb);
  235. extern int fat_statfs(struct super_block *sb,struct statfs *buf, int);
  236. extern void fat_write_inode(struct inode *inode);
  237.  
  238. /* dir.c */
  239. extern struct file_operations fat_dir_operations;
  240. extern int fat_readdirx(struct inode *inode, struct file *filp, void *dirent,
  241.             fat_filldir_t fat_filldir, filldir_t filldir,
  242.             int shortnames, int longnames, int both);
  243. extern int fat_readdir(struct file *filp,
  244.                void *dirent, filldir_t);
  245. extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
  246.              unsigned int cmd, unsigned long arg);
  247.  
  248. /* file.c */
  249. extern struct inode_operations fat_file_inode_operations;
  250. extern struct inode_operations fat_file_inode_operations_1024;
  251. extern struct inode_operations fat_file_inode_operations_readpage;
  252. extern ssize_t fat_file_read(struct file *, char *, size_t, loff_t *);
  253. extern ssize_t fat_file_write(struct file *, const char *, size_t, loff_t *);
  254. extern void fat_truncate(struct inode *inode);
  255.  
  256. /* mmap.c */
  257. extern int fat_mmap(struct file *, struct vm_area_struct *);
  258. extern int fat_readpage(struct file *, struct page *);
  259.  
  260.  
  261. /* vfat.c */
  262. extern int init_vfat_fs(void);
  263.  
  264.  
  265. /* msdosfs_syms.c */
  266. extern int init_msdos_fs(void);
  267. extern struct file_system_type msdos_fs_type;
  268.  
  269. /* msdos.c */
  270. extern struct super_block *msdos_read_super(struct super_block *sb,void *data, int silent);
  271.  
  272. /* msdos.c - these are for Umsdos */
  273. extern void msdos_read_inode(struct inode *inode);
  274. extern int msdos_lookup(struct inode *dir,struct dentry *);
  275. extern int msdos_create(struct inode *dir,struct dentry *dentry,int mode);
  276. extern int msdos_rmdir(struct inode *dir,struct dentry *dentry);
  277. extern int msdos_mkdir(struct inode *dir,struct dentry *dentry,int mode);
  278. extern int msdos_unlink(struct inode *dir,struct dentry *dentry);
  279. extern int msdos_unlink_umsdos(struct inode *dir,struct dentry *dentry);
  280. extern int msdos_rename(struct inode *old_dir,struct dentry *old_dentry,
  281.             struct inode *new_dir,struct dentry *new_dentry);
  282.  
  283. /* nls.c */
  284. extern int init_fat_nls(void);
  285. extern struct fat_nls_table *fat_load_nls(int codepage);
  286.  
  287. /* tables.c */
  288. extern unsigned char fat_uni2esc[];
  289. extern unsigned char fat_esc2uni[];
  290.  
  291. /* fatfs_syms.c */
  292. extern int init_fat_fs(void);
  293. extern void cleanup_fat_fs(void);
  294.  
  295. /* nls.c */
  296. extern int fat_register_nls(struct fat_nls_table * fmt);
  297. extern int fat_unregister_nls(struct fat_nls_table * fmt);
  298. extern struct fat_nls_table *fat_find_nls(int codepage);
  299. extern struct fat_nls_table *fat_load_nls(int codepage);
  300. extern void fat_unload_nls(int codepage);
  301. extern int init_fat_nls(void);
  302.  
  303. /* vfat/namei.c - these are for dmsdos */
  304. extern int vfat_create(struct inode *dir,struct dentry *dentry,int mode);
  305. extern int vfat_unlink(struct inode *dir,struct dentry *dentry);
  306. extern int vfat_unlink_uvfat(struct inode *dir,struct dentry *dentry);
  307. extern int vfat_mkdir(struct inode *dir,struct dentry *dentry,int mode);
  308. extern int vfat_rmdir(struct inode *dir,struct dentry *dentry);
  309. extern int vfat_rename(struct inode *old_dir,struct dentry *old_dentry,
  310.                struct inode *new_dir,struct dentry *new_dentry);
  311. extern void vfat_put_super(struct super_block *sb);
  312. extern struct super_block *vfat_read_super(struct super_block *sb,void *data,
  313.                        int silent);
  314. extern void vfat_read_inode(struct inode *inode);
  315. extern int vfat_lookup(struct inode *dir,struct dentry *);
  316.  
  317. /* vfat/vfatfs_syms.c */
  318. extern struct file_system_type vfat_fs_type;
  319.  
  320. #endif /* __KERNEL__ */
  321.  
  322. #endif
  323.